﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BGCOP.CAVTOP.BUSINESSLAYER
{
    public class MarcasVehiculo
    {
        public List<TMarcaVehiculo> ListarTodos()
        {
            masterDBACEntities db = new masterDBACEntities();
            var modv = from d in db.TMarcaVehiculo select d;
            return modv.ToList();
        }

        public void Agregar(string marcaNueva, DateTime fechaC, int usuarioUg)
        {
            masterDBACEntities db = new masterDBACEntities();
            TMarcaVehiculo tmp = new TMarcaVehiculo();
            tmp.NombreMarcaVehiculo  = marcaNueva;
            tmp.fechaUltimaGestion = fechaC;
            tmp.usuarioUltimaGestion = usuarioUg;
            db.AddToTMarcaVehiculo(tmp);
            db.SaveChanges();
        }

        public void Modificar(int id, string marcaNueva, DateTime fechaC, int usuarioUg)
        {

            masterDBACEntities db = new masterDBACEntities();
            TMarcaVehiculo te = db.TMarcaVehiculo.FirstOrDefault(c => c.idMarcaVehiculo == id);
            if (te != null)
            {
                te.NombreMarcaVehiculo  = marcaNueva;
                te.fechaUltimaGestion = fechaC;
                te.usuarioUltimaGestion = usuarioUg;
                db.SaveChanges();
            }
            
        }
        
        public void Eliminar(int id)
        {
            
            masterDBACEntities db = new masterDBACEntities();
            TMarcaVehiculo te = db.TMarcaVehiculo.FirstOrDefault(c => c.idMarcaVehiculo  == id);
            db.TMarcaVehiculo.DeleteObject(te);
            db.SaveChanges();
            
        }


    }
}
